package com.yumingjiang.weichatgtp.controller;

import com.yumingjiang.commontool.util.HttpClientResult;
import com.yumingjiang.weichatgtp.common.model.ChatCommonVO;
import com.yumingjiang.weichatgtp.common.model.ChatParam;
import com.yumingjiang.weichatgtp.service.ChatGPTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * [OpenAi聊天控制器]
 *
 * @author : [Administrator]
 * @version : [v1.0]
 * @createTime : [2023/3/9 23:31]
 */
@RestController
@RequestMapping("/openai")
public class OpenAiChatController {

    @Autowired
    private ChatGPTService chatGPTService;

    @RequestMapping(value = "/chat", method = RequestMethod.POST,produces = {"application/json"})
    public ChatCommonVO chat(@RequestBody ChatParam chatParam) {
        HttpClientResult chat = chatGPTService.chat(chatParam.getQueryCondition(),
                chatParam.getFilePath()+"/"+chatParam.getFileName());
        ChatCommonVO chatCommonVO = new ChatCommonVO();
        chatCommonVO.setSuccess(chat.isSuccess());
        chatCommonVO.setMessage(chat.getMessage());
        chatCommonVO.setContent(chat.getContent());
        chatCommonVO.setStatusCode(chat.getCode());
        return chatCommonVO;
    }
}
